package org.aurora.remote;

import org.aurora.remote.protocol.RemoteCommand;
import org.aurora.remote.protocol.RemoteCommandType;
import org.aurora.remote.protocol.RemoteRequest;
import org.aurora.remote.protocol.RemoteResponse;

public interface RemoteCommandHandler<COMMAND_CONTEXT extends RemoteCommandContext> {
    default void processor(COMMAND_CONTEXT context)  {
        RemoteCommand remoteCommand = context.getRemoteCommand();
        RemoteCommandType remoteCommandType = remoteCommand.getRemoteCommandType();

        switch (remoteCommandType) {
            case REQUEST: {
                context.setRemoteRequest((RemoteRequest) remoteCommand);
                processorRequest(context);
                break;
            }
            case RESPONSE: {
                context.setRemoteResponse((RemoteResponse) remoteCommand);
                processorResponse(context);
                break;
            }
            default: {
                // todo 异常
                break;
            }
        }
    }

    void processorRequest(COMMAND_CONTEXT context);

    void processorResponse(COMMAND_CONTEXT context);

    void start();

    void stop();
}
